<template>
  <div class="app">
    <div class="venue_wrap df_sb">
      <div class="df_ac" />
      <el-button :loading="subLoading" type="primary" @click="onSubmit">保存并发布</el-button>
    </div>
    <div class="mini_main df mt20">
      <div class="module_wrap">
        <div class="df_sb">
          <strong class="f_size18">底部导航模块</strong>
        </div>
        <div class="f_size12 mt10 mb10 placeholder9">该模块不可编辑</div>
        <div class="module_list">
          <template v-for="(item, index) in arr">
            <div
              :key="item.name"
              class="item active"
              @click="moduleItemClick(index)"
            >
              <template v-if="!item.isEdit">
                <div>
                  <span class="mr6">{{ item.name }}</span>
                </div>
              </template>
            </div>
          </template>
        </div>
      </div>
      <!-- <div class="simulator_wrap">
        <div class="simulator">
          <img src="@/icons/png/StatusBar.png" class="StatusBar">
          <div class="simulator_main">
            <tabHome :glabo-config="miniConfig" />
            <tabber />
          </div>
        </div>
      </div> -->
      <div class="option_wrap">
        <Modules ref="modulesRef" :template-id="templateId" />
      </div>
    </div>
  </div>
</template>

<script>
import Modules from './components-option/modules.vue'
import tabHome from '../home/components-option/tabHome.vue'
import tabber from './components-option/tabber.vue'
import { saveTabbarMiniTem } from '@/api'
export default {
  components: {
    tabber,
    tabHome,
    Modules
  },
  props: {
    templateId: {
      type: String,
      default: ''
    },
    meta: {
      type: Array,
      default: () => ([])
    }
  },
  data() {
    return {
      arr: [
        {
          name: '底部导航',
          nameTemp: '',
          isShow: true,
          isEdit: false
        }
      ],
      miniConfig: {},
      subLoading: false
    }
  },
  // watch: {
  //   config: {
  //     handler(newValue) {
  //       this.miniConfig = newValue
  //     },
  //     immediate: true,
  //     deep: true
  //   }
  // },
  methods: {
    onSubmit() {
      const temp = this.$refs.modulesRef.tabbarList.map(i => {
        const obj = {
          code: i.code,
          iconNoSelected: i.iconNoSelected,
          iconSelected: i.iconSelected,
          name: i.nameTemp,
          selected: i.selected,
          url: i.url
        }
        return obj
      })
      this.subLoading = true
      saveTabbarMiniTem({ param: {
        navigationList: temp,
        templateId: this.templateId
      }}).then(res => {
        this.subLoading = false
        if (res.errorCode !== '000000') return
        this.$message.success('保存成功')
        // this.$store.dispatch('app/resetMiniFlag')
        this.$refs.modulesRef.initTabbarList()
      }, () => {
        this.subLoading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.module_wrap {
  width: 300px;
  height: 100%;
  padding: 20px;
  background-color: #fff;
  font-size: 14px;
  .module_list {
    height: calc(100% - 20px);
    overflow-y: auto;
    &::-webkit-scrollbar {
      display: none;
    }
    width: 260px;
    .item {
      position: relative;
      width: 260px;
      height: 60px;
      padding: 0 20px;
      background: #ffffff;
      border: 1px solid #dfe2e8;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 10px;
      cursor: pointer;
      .item_icon {
        display: none;
        img {
          cursor: pointer;
        }
      }
      &:hover {
        .item_icon {
          display: block;
        }
        .item_icon_none {
          display: none;
        }
      }
      .input_wrap {
        position: relative;
        .text {
          position: absolute;
          top: 11px;
          right: 10px;
          font-size: 12px;
          color: #999999;
        }
        ::v-deep .el-input__inner {
          padding-right: 46px;
        }
      }
      .drag {
        position: absolute;
        width: 16px;
        height: 16px;
        left: 0;
        top: 0;
      }
    }
    .active {
      background: #f4f7fc;
      border: 1px solid #435ebe;
    }
  }
}
.simulator_wrap {
  width: 818px;
  height: 1464px;
  padding: 32px 34px;
  flex: none;
  background-color: #fff;
  position: relative;
  background: url("~@/icons/png/ic_shouji.png");
  background-size: 100% 100%;
  /* Old IE only */
  -moz-transform: scale(0.34);
  -webkit-transform: scale(0.34);
  transform: scale(0.34);
  transform-origin: top left;

  .simulator {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50px;
    overflow: hidden;
    background-color: #F7F7F7;

    .simulator_main {
      width: 100%;
      height: 100%;
      overflow-y: auto;

      &::-webkit-scrollbar {
        display: none;
      }
    }

    .StatusBar {
      height: 88px;
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 2;
    }
  }
}
.option_wrap {
  background-color: #fff;
  flex: 1;
}
.mini_main {
  /* background-color: #f5f6fd; */
  height: calc(100% - 140px);
}
.app {
  height: 100%;
}
</style>
